home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F18248_SubstringDDMMYYYY.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-10-04  |  4.2 KB  |  108 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- ===========================================================
  3.   Styelsheet:     SubstringDDMMYYYY.xsl
  4.   Category:       FilteringSorting
  5.   Sub-category:   DateSorting using Substring
  6.   Author:         David Silverlight
  7.                   HeadGeek@xmlpitstop.com
  8.   Created:        2001-05-16
  9.   Description:-
  10.     This stylsheet demonstrates how to use the substring
  11.     function to sort a date.  In this example, we are using a
  12.     3 part sort key for month, day and year.  Since we are
  13.     breaking it into 3 sections, we can easily control the order
  14.     (ascending or descending) for each part of our date.  In this
  15.     example, we are sorting by Day, Month, Year
  16. ================================================================ -->
  17. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  18.   <xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
  19.  
  20.   <xsl:template match="/">
  21.     <html>
  22.       <head>
  23.         <title>FilteringSorting - DateSorting using Substring</title>
  24.         <style type="text/css">
  25.           H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  26.           H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  27.           .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
  28.           .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  29.           .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
  30.           TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
  31.           TD {COLOR: darkblue; FONT-FAMILY: Arial}
  32.           TR { background-color: beige; }
  33.           BODY { background-color: beige; }
  34.         </style>
  35.       </head>
  36.       <body>
  37.         <h1>Display of transactions in order of Day, Month, Year (DDMMYYYY)</h1>
  38.         <span class="subhead">Start Dates</span>
  39.         <table border="1">
  40.           <tr>
  41.             <th>Transaction Start Date</th>
  42.             <th>Description</th>
  43.             <th>Day</th>
  44.             <th>Month</th>
  45.             <th>Year</th>
  46.           </tr>
  47.           <xsl:for-each select="/transactions/transaction">
  48.             <xsl:sort order="ascending" select="substring(@startdate, 9,2)" />
  49.             <xsl:sort order="ascending" select="substring(@startdate, 6,2)" />
  50.             <xsl:sort order="ascending" select="substring(@startdate, 1,4)" />
  51.             <tr>
  52.               <td>
  53.                 <xsl:value-of select="@startdate" />
  54.               </td>
  55.               <td>
  56.                 <xsl:value-of select="@description" />
  57.               </td>
  58.               <td>
  59.                 <xsl:value-of select="substring(@startdate, 9,2)" />
  60.               </td>
  61.               <td>
  62.                 <xsl:value-of select="substring(@startdate, 6,2)" />
  63.               </td>
  64.               <td>
  65.                 <xsl:value-of select="substring(@startdate, 1,4)" />
  66.               </td>
  67.             </tr>
  68.           </xsl:for-each>
  69.         </table>
  70.         <br />
  71.         <br />
  72.         <span class="subhead">End Dates</span>
  73.         <table border="1">
  74.           <tr>
  75.             <th>Transaction End Date</th>
  76.             <th>Description</th>
  77.             <th>Day</th>
  78.             <th>Month</th>
  79.             <th>Year</th>
  80.           </tr>
  81.           <xsl:for-each select="/transactions/transaction">
  82.             <xsl:sort order="ascending" select="substring(@enddate, 9,2)" />
  83.             <xsl:sort order="ascending" select="substring(@enddate, 6,2)" />
  84.             <xsl:sort order="ascending" select="substring(@enddate, 1,4)" />
  85.             <tr>
  86.               <td>
  87.                 <xsl:value-of select="@enddate" />
  88.               </td>
  89.               <td>
  90.                 <xsl:value-of select="@description" />
  91.               </td>
  92.               <td>
  93.                 <xsl:value-of select="substring(@enddate, 9,2)" />
  94.               </td>
  95.               <td>
  96.                 <xsl:value-of select="substring(@enddate, 6,2)" />
  97.               </td>
  98.               <td>
  99.                 <xsl:value-of select="substring(@enddate, 1,4)" />
  100.               </td>
  101.             </tr>
  102.           </xsl:for-each>
  103.         </table>
  104.       </body>
  105.     </html>
  106.   </xsl:template>
  107. </xsl:stylesheet>
  108.